import { reqGetHomeListData } from "@/api"

const state = {
    homeListData:[]
}
const mutations = {
    // 存储首页数据
    GET_HOME_LIST_DATA(state,payload){
        state.homeListData = payload.result
    }
}
const actions = {
    // 获取首页数据
    async getHomeListData(context){
        const result = await reqGetHomeListData()
        if(result.code === 200){
            // console.log(result);
            context.commit('GET_HOME_LIST_DATA',result)
        }else{
            console.log(result.message);
        }
    }
}
const getters = {
    // 准备轮播图数据
    bannerList(state){
        return state.homeListData[0]?.panelContents
    },
    // 准备推荐商品的内容
    oneRecommendList(state){
        return state.homeListData[1]?.panelContents
    },
    // 准备热门商品数据
    hotGoodsList(state){
        return state.homeListData[2]?.panelContents
    },
    // 楼层商品数据准备
    floorGoodsList(state){
        return state.homeListData.slice(3,6)
    },
    twoRecommendList(state){
        return state.homeListData[6]?.panelContents
    }
}

// 导出对象
export default {
    namespaced: true, // 既然分模块进行开发，一定要开启命名空间
    state,
    actions,
    mutations,
    getters,
}